/**
 * elancom Corporation copy right 2012 - 2015  
 *   
 * $Header$
 * $Id$
 * $Author$
 * $Date$
 * $Revision$
 */
package com.elancom.framework.web.context;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.filter.OncePerRequestFilter;


/**
 * @author elancom
 * @date 2012-7-23
 */
public final class RequestContextFilter extends OncePerRequestFilter {
	// private static RCCPurview RCCPurview = new RCCPurview();

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.web.filter.OncePerRequestFilter#doFilterInternal(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse,
	 * javax.servlet.FilterChain)
	 */
	@Override
	protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
		try {
			RequestContext.setContext(request, response, getServletContext());
			filterChain.doFilter(request, response);
		} finally {
			RequestContext.clear();
		}
	}

	// 技巧代码
	static final class RCCPurview {
		private RCCPurview() {
		}
	}
}
